package com.momo.interceptor;

import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Map;

/**
 * @author ：朱博
 * @description：数据拦截器，进行数据拦截
 * @date ：2021/3/28 12:51
 */
public class TimeInterceptor implements ProducerInterceptor<String,String> {
    /**
     * 配置的一些信息
     * @param map
     */
    @Override
    public void configure(Map<String, ?> map) {

    }
    /**
     * 拦截生产后的一些消息处理
     * @param producerRecord
     * @return
     */
    @Override
    public ProducerRecord<String, String> onSend(ProducerRecord<String, String> producerRecord) {
        //1、取出数据
        String value = producerRecord.value();
        //2、创建新的对象进行修改
        ProducerRecord producerRecord1 = new ProducerRecord<>(
                                            producerRecord.topic(),
                                            producerRecord.partition(),
                                            producerRecord.key(),
                                        value+","+System.currentTimeMillis());

        return producerRecord1;
    }

    /**
     *
     * @param recordMetadata
     * @param e
     */
    @Override
    public void onAcknowledgement(RecordMetadata recordMetadata, Exception e) {

    }

    /**
     * 关闭发送后
     */
    @Override
    public void close() {

    }

}
